from manim import *


class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        
        #镜头跟进效果 
        self.camera.frame.save_state()

        

        text = Tex(r"\text{(张1000)设函数}$f\left( x,y\right) =2e^{x^{2}y}-e^{x}-e^{-x}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,25,0])
        
        text1 = Tex(r"\text{(1)计算}$\lim\limits _{x\rightarrow 0}\dfrac{f\left( x,y\right) }{x^{2}}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,18,0])
        
        
        text2 = Tex(r"\text{(2)}$f\left( x,y\right) $\text{在点}$\left( 0,0\right) $\text{处是否取得极值?}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,11,0])
        self.play(Write(text2),Write(text),Write(text1))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)

        text3 = Tex(r"$=2y-1$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text1,RIGHT,buff=5)
        self.play(Write(text3))

        text4 = Tex(r"$f_{x}=4xye^{x^{2}y}-e^{x}+e^{x}=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,5,0])
        text5 = Tex(r"$f_{y}=2x^{2}e^{x^{2}y}=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35.5,-5,0])
        text6 = Tex(r"\text{得驻点}$\left( 0,0\right) $",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-6,0,0])
        text7 = Tex(r"$f_{xx}\left( 0,0\right) =0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([11,5,0])
        text8 = Tex(r"$f_{xy}\left( 0,0\right) =0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([11,0,0])
        text9 = Tex(r"$f_{yy}\left( 0,0\right) =0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([11,-5,0])
        self.play(Create(text4),Create(text5))
        self.play(Create(text6))
        text10 = Tex(r"$AC-B^{2}=0$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([29,0,0])
        text11 = Tex(r"\text{(失效)}",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text10,RIGHT,buff=1)
        self.play(Create(text7),Create(text8),Create(text9))
        self.play(Write(text10))
        self.play(Write(text11))
        text12 = Tex(r"$\lim\limits _{\left( x,y\right) \rightarrow \left( 0,0\right) }\dfrac{f\left( x,y\right) }{x^{2}}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,-15,0])
        self.play(Write(text12))
        text13 = Tex(r"$=-1$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text12,RIGHT,buff=1)
        self.play(Write(text13))
        text14 = Tex(r"$>0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).move_to([-15,-22,0])
        self.play(Write(text14))
        text15 = Tex(r"$<0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text13,RIGHT,buff=2)
        self.play(Write(text15))
        text16 = Tex(r"$<0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).move_to([-15,-8,0])
        self.play(Write(text16))
        text17 = Tex(r"$=f\left( 0,0\right) $",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text16,RIGHT,buff=1)
        self.play(Write(text17))
        text18 = Tex(r"$f\left( 0,0\right) $\text{是极大值}",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(10.0).next_to(text15,RIGHT,buff=8)
        self.play(Write(text18))

        self.wait()